package com.itheima.d3_transform_stream;

import java.io.*;
import java.nio.charset.Charset;
import java.util.Calendar;

/*
     目标：掌握字符输出转换流的使用。

     构造器
        public OutputStreamWriter(OutputStream os)	可以把原始的字节输出流，按照代码默认编码转换成字符输出流。
        public OutputStreamWriter(OutputStream os，String charset)	可以把原始的字节输出流，按照指定编码转换成字符输出流(重点)
 */
public class OutputStreamWriterTest3 {
    public static void main(String[] args) {
        /*try(FileOutputStream fos = new FileOutputStream("ccc.txt");
            OutputStreamWriter osw  = new OutputStreamWriter(fos, "GBK")
        ){
            osw.write("你好，中国");

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }*/
       try(FileWriter fw = new FileWriter("ccc.txt", Charset.forName("GBK"))){
            fw.write("你好，中国");

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
